# Maintainer: Jiachen Yang <farseerfc@gmail.com>
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Håvard Pettersson <mail@haavard.me>
# Contributor: naxuroqa <naxuroqa at gmail.com>
# Contributor: Boohbah <boohbah at gmail.com>
# Contributor: Kevin MacMartin <prurigro at gmail dot com>

pkgname=toxcore
_pkgname=c-toxcore
epoch=1
pkgver=0.2.18
pkgrel=2
pkgdesc='Secure, configuration-free, P2P Skype replacement backend'
arch=('loong64' 'x86_64')
url='https://tox.chat'
license=('GPL3')
depends=('systemd' 'libconfig' 'libsodium' 'libvpx' 'opus')
makedepends=('check' 'cmake')
conflicts=("tox")
provides=("tox")
backup=('etc/tox-bootstrapd.conf')
source=(
	"${_pkgname}-v${pkgver}.tar.gz::https://github.com/TokTok/${_pkgname}/releases/download/v${pkgver}/${_pkgname}-${pkgver}.tar.gz"
	"${_pkgname}-v${pkgver}.tar.gz.asc::https://github.com/TokTok/${_pkgname}/releases/download/v${pkgver}/${_pkgname}-${pkgver}.tar.gz.asc"
	#"${_pkgname}-v${pkgver}.tar.lz::https://github.com/TokTok/${_pkgname}/releases/download/v${pkgver}/${_pkgname}-v${pkgver}.tar.lz"
	#"${_pkgname}-v${pkgver}.tar.lz.asc::https://github.com/TokTok/${_pkgname}/releases/download/v${pkgver}/${_pkgname}-v${pkgver}.tar.lz.asc"
        'toxcore.conf'
        'toxcore.tmpfiles')
sha512sums=('e9b0d73a2e0460290c8453a0a64fc91deed2e0cf87f945d0ba203b929f19a296571d7140f4df89b06f7e67f2b61894460ce4dd32ab9ecf6ea7d5b67538fadb23'
            'SKIP'
            'aa1dcfbdf9b613f5d89e238ff5d01e0ea150ad3162792acb806f51ce07fd9ade1270b310b1285a828dcdf578549b95a89fd9bd198fb205c83f5a5be2c969ea63'
            'f1534f5f46d0b8e2f21b2bce802f48a8bd45ba6beca34112d44e27b6033352867cd9d25f1c3c35c59faf6e6d727793f3d552d0d9b724c9d09cb83075ca196743')
validpgpkeys=(
'15D3B9A6B3951DF9854FCA93E786548AE0A0B56B'  # RobinLindén<mail+gitlab@robinlinden.eu>
'B7008FF12C079BF6E6EA19D1601A604B7E605776'  # Robin Lindén <mail@robinlinden.eu>
# GPG key fingerprints taken from https://github.com/qTox/qTox/blob/$_gitver/README.md
'DA262CC93C0E1E525AD21C8596775D454B8EBF44'  # sudden6 <sudden6@gmx.at>
'BA7883E22F9D35945BA3376053137C3033F09008'  # Zetok Zalbavar <zetok@openmailbox.org>
'1157616BBD860C539926F8139591A163FF9BE04C'  # - antis81
'31039166FA902CA50D05D6085AF9F2E29107C727'  # - Diadlo
'C7A2552D0B250F983827742C133203A3AC399151'  # - initramfs
'2880C860D95C909D3DA45C687E086DD661263264'  # - tux3
)

prepare() {
  cd $_pkgname-$pkgver
  sed -i "s|/usr/local|/usr|" other/bootstrap_daemon/tox-bootstrapd.service
  sed -i "/Rpath/d;/RPATH/d" CMakeLists.txt
}

build() {
  cd $_pkgname-$pkgver/build
  cmake -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_INSTALL_LIBDIR=/usr/lib \
        -DDHT_BOOTSTRAP=on \
        -DBOOTSTRAP_DAEMON=on \
        -DBUILD_TOXAV=on \
        -DBUILD_AV_TEST=on ..
  make
}

check() {
  cd $_pkgname-$pkgver/build
  make test 
}

package() {
  cd $_pkgname-$pkgver/build
  make DESTDIR="$pkgdir" install
  install -Dm644 "$srcdir/toxcore.conf" "$pkgdir/usr/lib/sysusers.d/toxcore.conf"
  install -Dm644 "$srcdir/toxcore.tmpfiles" "$pkgdir/usr/lib/tmpfiles.d/toxcore.conf"
  install -Dm644 ../other/bootstrap_daemon/tox-bootstrapd.service "$pkgdir/usr/lib/systemd/system/tox-bootstrapd.service"
  install -Dm644 ../other/bootstrap_daemon/tox-bootstrapd.conf "$pkgdir/etc/tox-bootstrapd.conf"
}
